using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Markup;
using Rhizome.Contract;
using Rhizome.Contract.Diag;
using Rhizome.Model.Validation;

namespace Rhizome.Model
{
	[ContentProperty("Event")]
	public sealed class CastEvent : EventActionBase<object>, IValidate, IEventsDiag
    {
        public CastEvent(object @event)
        {
            Event = @event;
        }

        public CastEvent()
        {
        }

        public object Event { get; set; }

        public override void Process()
        {
            EventSink.CastEvent(this, Event);
        }

        [DebuggerStepThrough]
        public override object GetForwardEvent()
        {
            return Event;
        }

    	#region Implementation of IValidate

    	IEnumerable<IValidationResult> IValidate.GetValidationResults()
    	{
			if (Event == null)
				yield return ValidationResult.EventNotSet;
    	}

    	#endregion

    	#region Implementation of IInitFromString

		public void Init(string s)
    	{
    		Event = s;
    	}

    	#endregion

		public override string ToString()
		{
			return string.Format("CastEvent {0}", Event);
		}

		#region Implementation of IEventsDiag

		IEnumerable<object> IEventsDiag.Events
		{
			[DebuggerStepThrough]
			get { yield return Event; }
		}

		#endregion
    }

#if !SILVERLIGHT && !WINDOWS_PHONE
    public sealed class CastEventExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return new CastEvent(Event);
        }

        public object Event { get; set; }
    }
#endif
}